package com.payment.ktb.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.payment.ktb.R;
import com.payment.ktb.model.OrderCenterEntity;
import com.payment.ktb.utils.LogUtil;

import java.util.List;

/**
 * Created by admin on 2017/9/3.
 */

public class OrderCenterAdapter extends BaseAdapter{

    private Context context;
    private List<OrderCenterEntity> listdata;
    private static final int TYPE_COUNT = 2;//item类型的总数
    private static final int TYPE_DATE = 0;//时间
    private static final int TYPE_ITEM = 1;//条目
    public OrderCenterAdapter() {
    }

    public OrderCenterAdapter(Context context, List<OrderCenterEntity> listdata) {
        this.context = context;
        this.listdata = listdata;
    }

    @Override
    public int getCount() {
        return listdata.size();
    }

    @Override
    public Object getItem(int i) {
        return listdata.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getViewTypeCount() {
        return TYPE_COUNT;
    }

    @Override
    public int getItemViewType(int position) {

        if (!TextUtils.isEmpty(listdata.get(position).getDate())){
            return TYPE_DATE;
        }else {
            return TYPE_ITEM;
        }

    }




    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        int itemViewType = getItemViewType(i);

            switch (itemViewType){

                case TYPE_DATE:
                    view = View.inflate(context,R.layout.adapter_ordercenter_date_item,null);
                    TextView tv_ordercenter_adapter_item1_time = (TextView) view.findViewById(R.id.tv_ordercenter_adapter_date);
                    tv_ordercenter_adapter_item1_time.setText(listdata.get(i).getDate());
                    break;

                case TYPE_ITEM:
                    view = View.inflate(context,R.layout.adapter_ordercenter_content_item,null);
                    TextView tv_ordercenter_adapter_item2_typename = (TextView) view.findViewById(R.id.tv_ordercenter_orderType);
                    TextView tv_ordercenter_adapter_item2_amount = (TextView) view.findViewById(R.id.tv_ordercenter_amount);
                    TextView tv_ordercenter_adapter_item2_time = (TextView) view.findViewById(R.id.tv_ordercenter_orderReqTime);
                    TextView tv_ordercenter_adapter_item2_status = (TextView) view.findViewById(R.id.tv_ordercenter_orderStatusName);


                    if ("1000".equals(listdata.get(i).getProduct())) {
                        tv_ordercenter_adapter_item2_typename.setText("商户收款");
                    }else if ("1001".equals(listdata.get(i).getProduct())) {
                        tv_ordercenter_adapter_item2_typename.setText("会员购买");
                    }else if ("1002".equals(listdata.get(i).getProduct())) {
                        tv_ordercenter_adapter_item2_typename.setText("后台管理费");
                    }else {
                        tv_ordercenter_adapter_item2_typename.setText("商户收款");
                    }


                    tv_ordercenter_adapter_item2_amount.setText("¥ " + listdata.get(i).getPrice());
                    tv_ordercenter_adapter_item2_time.setText(listdata.get(i).getTime());
                    if (listdata.get(i).getStatus().equals("支付失败")) {
                        tv_ordercenter_adapter_item2_status.setTextColor(context.getResources().getColor(R.color.red));
                    }else if (listdata.get(i).getStatus().equals("支付成功")) {
                        tv_ordercenter_adapter_item2_status.setTextColor(context.getResources().getColor(R.color.green));
                    }else {
                        tv_ordercenter_adapter_item2_status.setTextColor(context.getResources().getColor(R.color.text666666));
                    }
                    tv_ordercenter_adapter_item2_status.setText(listdata.get(i).getStatus());
                    break;
            }

        return view;
    }













    class ViewHolderDate {
        TextView tv_ordercenter_adapter_item1_time;
    }

    class ViewHolderItem {
        TextView tv_ordercenter_adapter_item2_typename;
        TextView tv_ordercenter_adapter_item2_amount;
        TextView tv_ordercenter_adapter_item2_time;
        TextView tv_ordercenter_adapter_item2_status;
    }

}
